package com.ftg.learn.chapter04;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * 快排
 *
 * @author lijiaxin
 * @version 1.0
 * @date 2023/5/27 9:34
 */

public class QuickSort {

    public static void main(String[] args) {

        int[] arr={10,13,30,4,5,9,23,1,6,7,19,34};
        int middle= arr.length>>1;
        int mval=arr[middle];
        int left=0;
        int right= arr.length-1;
        while (true){
            //首先找到left对应的数据 大于middle
            while (left<right&&arr[left]<mval){
                left++;
            }
            //再找到right对应的数据 小于middle
            while (right>left&&arr[right]>mval){
                right--;
            }
            if(right<=left){
                break;
            }
            //            交换
            arr[right]=arr[left]+arr[right];
            arr[left]=arr[right]-arr[left];
            arr[right]=arr[right]-arr[left];
        }
        System.out.println(Arrays.toString(arr));
    }
}





